import math
class Trig(object):

    def drawCircle(self, centerX, centerY, radius, num_segments):
        """approximates a circle as a regular polygon with number of sides=num_segments 
            returns a list of vertices as a list of tuples. Data is generated counter clockwise
            thanks http://slabode.exofire.net/circle_draw.shtml"""
        segments=[]
        for i in  range(num_segments,0,-1):
            theta = (2.0 * math.pi * (i-1)) / num_segments
            x = radius * math.cos(theta)
            y = radius * math.sin(theta) 
            segments.append((x + centerX, y + centerY))
        return segments
    
    def createBrickCircle(self, centerX, centerY, inner_radius,outer_radius, num_segments):
        """generates the vertices for two circle approximations then takes two points at a time from
            both the inner and outer circle and stores them as a list of tuples all of len 4
        """
        #draw inner circle
        innerList=self.drawCircle(centerX, centerY, inner_radius, num_segments)
        #draw outer circle
        outerList=self.drawCircle(centerX, centerY, outer_radius, num_segments)
        mergedList=[]
        for i in range(len(innerList)):
            try:
                thisBrick=outerList[i],outerList[i+1],innerList[i+1],innerList[i]
            except:
                thisBrick=outerList[i],outerList[0],innerList[0],innerList[i]               
            
            mergedList.append(thisBrick)    
        return mergedList        
                
def worldvec_to_screen(pt):
    """converts world vector points to screen.  Only for 800x600 and 80x60 world"""
    return (int((pt.x)*10 + 400), int(600-(pt.y)*10 - 300))

def worldtup_to_screen(pt):
    """converts world tuple to screen.  Only for 800x600 and 80x60 world"""
    return [int((pt[0])*10 + 400), int(600-(pt[1])*10 - 300)]

def shape_to_screen(shape):
    return worldvec_to_screen(shape.GetBody().GetWorldPoint(shape.localPosition)) 


def screen_to_worldtup(pt):
    """converts screen to world.  Only for 800x600 and 80x60 world"""
    return ((pt[0]-400)/10.0 , (-pt[1]+300)/10.0)

def shapevert_to_screen(shape):
    """returns list of screen coordinates for all vertices of a box2d shape. Only for 800x600 and 80x60 world""" 
    return [worldvec_to_screen(shape.GetBody().GetWorldPoint(localPoint)) for localPoint in shape.vertices]
                
def main():
    #import Box2D
    myTrig=Trig()
    list=myTrig.drawCircle(10,10,10,10)
    print list
    list=myTrig.createBrickCircle(10,10,6,10,10)
    for brick in list:
        print brick
if __name__ == '__main__': main()
